package com.liuwei.msmall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.liuwei.msmall.common.utils.PageUtils;
import com.liuwei.msmall.common.utils.Query;
import com.liuwei.msmall.product.dao.AttrAttrgroupRelationDao;
import com.liuwei.msmall.product.entity.AttrAttrgroupRelationEntity;
import com.liuwei.msmall.product.service.AttrAttrgroupRelationService;
import com.liuwei.msmall.product.vo.AttrVo;
import com.liuwei.msmall.product.vo.req.AttrAttrgroupRelationReq;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupRelationEntity> page = this.page(
                new Query<AttrAttrgroupRelationEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationEntity>()
        );

        return new PageUtils(page);
    }


    @Override
    public void removeRelationBatch(List<AttrAttrgroupRelationReq> relationVos) {
        if (CollectionUtils.isEmpty(relationVos)){
            return;
        }
        relationVos.stream().forEach(relation->{
            this.remove(new LambdaQueryWrapper<AttrAttrgroupRelationEntity>()
                    .eq(AttrAttrgroupRelationEntity::getAttrId,relation.getAttrId())
                    .eq(AttrAttrgroupRelationEntity::getAttrGroupId,relation.getAttrGroupId()));

        });

    }


}
